// cookies
//设置cookie,增加到vue实例方便全局调用

  const setCookie=(c_name, value, expiredays)=>{
    const exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
  }
  // 删除
  const delCookie=(name)=> {
    const exp = new Date();
    exp.setTime(exp.getTime() - 1);
    const cval = getCookie(name);
    if (cval !== null) {
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
  }
  // 读取
 const  getCookie=(name)=> {
    const arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"))
    if (arr !== null) {
      return arr[2] + ""
    } else {
      return null
    }

}

export {setCookie,delCookie,getCookie};
